//index.js
//获取应用实例
const app = getApp()
Page({
  data: {
    imgUrls: [
      // "../../images/banner.png",
      // "../../images/banner.png",
      // "../../images/banner.png",
    ],
    autoplay: true,
    interval: 5000,
    duration: 1000,
    circular: true,
    coupondisplay: 'block',
    classifications:[
      // "../activity/activity"
      { url: "../yuyue/yuyue", src: "../../images/yuyue.png", text: "预约", types:'navigate',huodong:'tz1' },
      { url: "../order/order", src: "../../images/diancan.png", text: "点餐", types: 'switchTab', huodong: 'tz2' },
      { url: "../facePay/facePay", src: "../../images/dangmianfu.png", text: "当面付", types: 'navigate', huodong: 'tz3' }, 
      { url: "../index/index", src: "../../images/huodong.png", text: "活动", types: 'switchTab', huodong: 'huodong' },
      { url: "../index/index", src: "../../images/miaosha.png", text: "秒杀", types: 'navigate', huodong: 'huodong'  },
      { url: "../index/index", src: "../../images/pintuan.png", text: "拼团", types: 'navigate', huodong: 'huodong' },
      { url: "../index/index", src: "../../images/choujiang.png", text: "抽奖", types: 'navigate', huodong: 'huodong'  },
      { url: "../newMan/newMan", src: "../../images/xinren.png", text: "新人专享", types: 'navigate', huodong: 'tz8' },
    ],
    coupon:{},
    specials:[],
    recommends:[]
  },
  onLoad: function () {
    var that = this;

    // 轮播
    wx.request({
      url: app.globalData.directory + 'api/v2/banner/1', //仅为示例，并非真实的接口地址
      data: {
       
      },
      header: {
        'content-type': 'application/json', // 默认值
        'token': wx.getStorageSync('token')
      },
      success: function (res) {
       // console.log('123',res);
        if (res.data.status == 'ok') {
         //  console.log('11',res.data);
          that.setData({
            imgUrls:res.data.data.item
          })
        } else {
          wx.showToast({
            title: '请求失败,请稍候',
            icon: 'none',
            duration: 2000,
          })
        }
      }
    });
    // setTimeout(function(){     
    //   if (app.globalData.coupon.status == 'ok') {
        // 优惠券
        // wx.request({
        //   url: app.globalData.directory + 'api/v2/getNewActivity', //仅为示例，并非真实的接口地址
        //   data: {
        //   },
        //   header: {
        //     'content-type': 'application/json', // 默认值
        //     'token': wx.getStorageSync('token')
        //   },
        //   success: function (res) {
        //     if (res.data.status == 'ok') {
        //        //console.log('22', res.data.data);
        //       if (!res.data.data.is_have_coupon == 0) {
        //       that.setData({
        //         coupon: res.data.data,
        //         coupondisplay: 'block'
        //       })
        //       } else {
        //         that.setData({
        //           coupondisplay: 'none'
        //         })
        //       }

        //     } else {
        //       wx.showToast({
        //         title: '请求失败,请稍候',
        //         icon: 'none',
        //         duration: 2000,
        //       })
        //     }
        //   }
        // });
      // } else {
      //   that.setData({
      //     coupondisplay: 'none'
      //   })
      // }
    // },1000)

 
    // 美食专题
    wx.request({
      url: app.globalData.directory + 'api/v2/special/getspecial', //仅为示例，并非真实的接口地址
      data: {
      },
      header: {
        'content-type': 'application/json', // 默认值
        'token': wx.getStorageSync('token') // 存储是指定的token
      },
      success: function (res) {
        //console.log(res); //后台return的$result
        if (res.data.status == 'ok') {
           //console.log('33', res.data.data);
          that.setData({
            specials: res.data.data
          })
        } else {
          wx.showToast({
            title: '请求失败,请稍候',
            icon: 'none',
            duration: 2000,
          })
        }
      }
    });

    // 推荐菜品
    wx.request({
      url: app.globalData.directory + 'api/v2/getHomePageRecommend', //仅为示例，并非真实的接口地址
      data: {
      },
      header: {
        'content-type': 'application/json', // 默认值
        'token': wx.getStorageSync('token')
      },
      success: function (res) {
        console.log(res);
        if (res.data.status == 'ok') {
           console.log('44', res.data.data);
          that.setData({
            recommends:res.data.data
          })
        } else {
          wx.showToast({
            title: '请求失败,请稍候',
            icon: 'none',
            duration: 2000,
          })
        }
      }
    });
  },
  huodong:function(){
    wx.showToast({
      title: '此活动暂未开启',
      icon: 'none',
      duration: 2000,
    })
  },
 onShareAppMessage: function () {

  }
})  
